package com.changpay.zywy.ui.activity.freeze

import android.graphics.Color
import android.view.View
import com.changpay.zywy.R
import com.changpay.zywy.base.BaseActivity
import com.changpay.zywy.base.IView
import com.changpay.zywy.bean.FreezeMyDetailBean
import com.changpay.zywy.ext.showToast
import com.changpay.zywy.ext.sss
import com.changpay.zywy.http.RetrofitHelper
import kotlinx.android.synthetic.main.activity_freeze_detail.*
import kotlinx.android.synthetic.main.title_layout.*
import org.jetbrains.anko.textColor
import java.util.HashMap


class FreezeDetailActivity : BaseActivity(), IView {
    override fun attachLayoutRes(): Int {
        return R.layout.activity_freeze_detail
    }

    override fun showLoading() {

    }

    override fun hideLoading() {

    }

    override fun showDefaultMsg(msg: String) {
        showToast(msg)
    }

    override fun showMsg(msg: String) {
        showToast(msg)
    }

    override fun showError(errorMsg: String) {
        showToast(errorMsg)
    }


    override fun initData() {


    }

    override fun initView() {
        tv_title.text = intent.getStringExtra("title")
        iv_back.setOnClickListener { finish() }
        btn_jiedong.setOnClickListener {
            val params = HashMap<String, String>()
            params["key"] = token
            params["id"] = intent.getStringExtra("id")
            RetrofitHelper.service.freeze_cancel(params).sss(this)
            {
               showToast(it.result.toString())
                finish()
            }
        }
    }

    override fun start() {
        loadData()

    }

    private fun loadData() {
        val params = HashMap<String, String>()
        params["key"] = token
        params["id"] = intent.getStringExtra("id")
        RetrofitHelper.service.get_freeze_detail(params).sss(this)
        {
            setViewData(it.result.freeze_detail)
        }
    }


    private fun setViewData(data: FreezeMyDetailBean.FreezeDetailBean) {
        tv_one.text = data.apply_member_name
        tv_two.text = data.member_name
        tv_three.text = data.member_mobile
        tv_four.text = data.created_time
        tv_five.text = data.created_time
        tv_six.text = data.update_time
        tv_seven.text = data.freeze_amount
        when {
            data.status == 0 -> {
                tv_eight.text = "冻结中"
                tv_eight.textColor = Color.parseColor("#FABF13")
            }
            data.status == 1 -> {
                tv_eight.text = "已还款"
                tv_eight.textColor = Color.parseColor("#CEB388")
            }
            data.status == 2 -> {
                tv_eight.text = "已取消"
                tv_eight.textColor = Color.parseColor("#CEB388")
            }
        }

        if (data.is_cancel == 0)
        {
            btn_jiedong.visibility = View.GONE
        }else
        {
            btn_jiedong.visibility = View.VISIBLE
        }

    }
}
